#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

for i in sys.stdin:
    t=i.strip().split('\t',8)
    if len(t)==9:
        cid,sid,day,value,session,pv,nasid,visit_time,conversion=t
        value_list=value.strip().split('\001')
        actions={}
        for j in value_list:
            tmp=j.strip().split(',',2)
            if len(tmp)==3:
                time,customize,query=tmp
                if customize and customize.isdigit() and 1<=int(customize)<=3:
                    actions[time]=[1,customize]
                if query and len(query)>0:
                    actions[time]=[0,query]
        
        query_flag=False
        query_tmp=''
        for k,v in sorted(actions.iteritems()):
            if v[0]==0:
                query_flag=True
                query_tmp=v[1]
                continue
            if v[0]==1:
                if query_flag:
                    print '\t'.join(map(str,[cid,sid,day,'1',v[1],query_tmp,session,pv,nasid,visit_time,conversion]))
                